/*
 * @Description: 取消订单   CancellationOrder
 * @version: 
 * @Company: 
 * @Author: ZhengZhuang
 * @Date: 2019-08-28 15:02:30
 * @LastEditors: zhengzhuang
 * @LastEditTime: 2020-08-04 10:14:49
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/service/request.dart';

class CancellationOrder extends StatefulWidget {
  final String orderId;
  CancellationOrder({this.orderId});
  @override
  _CancellationOrderState createState() => _CancellationOrderState();
}

class _CancellationOrderState extends State<CancellationOrder> {
  /// 取消订单原因
  String cancellationReason = '等候较久';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('取消订单'),
      ),
      body: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Container(
              padding: EdgeInsets.all(ScreenUtil().setWidth(30.0)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    '取消本次乘客行程的原因',
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(30.0),
                      color: Colors.black54,
                    ),
                  ),
                  Container(
                    child: Card(
                      child: Column(
                        children: <Widget>[
                          RadioListTile<String>(
                              title: Text('等候较久'),
                              value: '等候较久',
                              groupValue: cancellationReason,
                              activeColor: Colors.black54,
                              onChanged: (value) {
                                setState(() {
                                  cancellationReason = value;
                                });
                              }),
                          RadioListTile<String>(
                              value: '联系不上乘客',
                              title: Text('联系不上乘客'),
                              groupValue: cancellationReason,
                              activeColor: Colors.black54,
                              onChanged: (value) {
                                setState(() {
                                  cancellationReason = value;
                                });
                              }),
                          RadioListTile<String>(
                              value: '其他原因',
                              title: Text('其他原因'),
                              groupValue: cancellationReason,
                              activeColor: Colors.black54,
                              onChanged: (value) {
                                setState(() {
                                  cancellationReason = value;
                                });
                              }),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
            InkWell(
                child: Container(
                  width: ScreenUtil().setWidth(750.0),
                  height: ScreenUtil().setWidth(120.0),
                  color: Color.fromARGB(255, 147, 155, 166),
                  alignment: Alignment.center,
                  child: Text(
                    '确认取消',
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(36.0),
                      color: Colors.white,
                    ),
                  ),
                ),
                onTap: () {
                  openAlertDialog(context);
                })
          ],
        ),
      ),
    );
  }

  // 取消订单
  Future openAlertDialog(context) async {
    final action = await showDialog(
        context: context,
        barrierDismissible: false, // 点击空白处是否可以关闭
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text('你确定要取消当前订单？'),
            actions: <Widget>[
              FlatButton(
                child: Text('再想想'),
                onPressed: () {
                  Navigator.pop(context, 'cancel');
                },
              ),
              FlatButton(
                child: Text('取消订单'),
                onPressed: () {
                  Navigator.pop(context, 'ok');
                },
              ),
            ],
          );
        });

    switch (action) {
      case 'ok':
        Request.driverCancelOrderFun(
            context: context,
            orderId: widget.orderId,
            cancellationReason: cancellationReason);
        break;
      case 'cancel':
        break;
      default:
    }
  }
}
